<template>
    <view>
        <uv-loading-page v-if="loading" :loading="loading" loading-mode="circle" loadingText="加载中..."></uv-loading-page>
        <view v-else class="m-4">
            <template v-if="article.images.length">
                <uv-swiper :list="article.images"></uv-swiper>
                <uv-divider :dashed="true"></uv-divider>
            </template>
            <uv-parse :content="article.theContent"></uv-parse>
        </view>

    </view>
</template>
<script setup lang="ts">
import { ref, defineProps } from 'vue'
import { onReady } from '@dcloudio/uni-app'
import { list } from '@/services/article'
import { convertToJson } from '@/utils/index'

const loading = ref(true)
const article = ref({
    title: '',
    images: '',
    theContent: '',
    createDate: ''
})

const props = defineProps({
    search: {
        type: String
    }
})


onReady(() => {

    uni.setNavigationBarTitle({
        title: props.search
    })

    list({ search: props.search }).then(({ rows }) => {
        if (rows[0]) {
            rows[0].images = convertToJson(rows[0].images, 'array')
            article.value = rows[0]
        } else {
            uni.showToast({
                title: '数据缺失',
                icon: 'none'
            })
        }
    }).catch(() => { }).finally(() => { loading.value = false })
})


</script>